package com.wwg.market.ui.member.client.item;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;
import com.mobileares.midp.widgets.client.button.CButton;
import com.mobileares.midp.widgets.client.textbox2.TextBoxLabel;
import com.wwg.market.ui.member.client.item.widgets.MemberListTable;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @author gaoyang
 * @version $Id: $
 * @date 12-2-26 上午1:36
 */
public class MemberListPage extends Composite implements PageBuilder {
    private MemberListTable listTable;
    private Map<String, String> paraMap = new HashMap<String, String>();

    public MemberListPage() {
        FlowPanel container = new FlowPanel();
        container.add(getHeaderPanel());
        container.add(getSearchPanel());
        container.add(getContentPanel());
        container.add(getFooterPanel());

        initModel();
        initWidget(container);
    }

    private void initModel() {
        listTable.render(paraMap);
    }

    public Panel getHeaderPanel() {
        FlowPanel panel = new FlowPanel();
        panel.addStyleName("pageHeader");
        Widget title = new HTML("【会员管理】");
        title.addStyleName("pageHeader_title");
        panel.add(title);
        return panel;
    }

    public Panel getSearchPanel() {
        HorizontalPanel panel = new HorizontalPanel();
        final TextBoxLabel username = new TextBoxLabel("会员名:");
        username.setWidth("450px");
        username.getLabelWidget().setWidth("100px");
        FlowPanel queryPanel = new FlowPanel();
        CButton query = new CButton("查询");

        query.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent clickEvent) {
                paraMap.clear();
                paraMap.put("username", (String) username.getValue());
                listTable.render(paraMap);
            }
        });
        queryPanel.add(query);

        panel.add(username);
        panel.add(queryPanel);
        return panel;
    }

    public Panel getContentPanel() {
        FlowPanel panel = new FlowPanel();
        listTable = new MemberListTable();
        panel.add(listTable);
        return panel;
    }

    public Panel getFooterPanel() {
        FlowPanel panel = new FlowPanel();

        SimplePanel separator = new SimplePanel();
        separator.addStyleName("pageFooter_separator");

        SimplePanel copyright = new SimplePanel();
        copyright.addStyleName("pageFooter");
        copyright.setWidget(new HTML("版权所有：** <br>" +
                "Copyright © 2012-2020 By ** All Rights Reserved\n"));

        panel.add(separator);
        panel.add(copyright);
        return panel;
    }
}
